﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="List.aspx.cs" Inherits="X.WebSite.Product.List"
    MasterPageFile="~/Master/Master.Master" %>

<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" ID="cph" runat="server">
    <h1>
        <asp:Label ID="lblCategoryName" runat="server"></asp:Label></h1>
    <p>
        <asp:Label ID="lblCategoryDescription" runat="server"></asp:Label></p>
    <table border="0" cellpadding="0" cellspacing="0">
        <%
            string categoryName = string.Empty;

            if (!string.IsNullOrEmpty(Request.QueryString["CategoryName"]))
                categoryName = Request.QueryString["CategoryName"];

            int categoryId = 0;

            categoryName = X.Common.StringUtils.UrlToString(categoryName, ref categoryId);

            System.Collections.Generic.IList<X.Entity.ProductInfo> list;

            if (0 != categoryId)
                list = X.Bll.Product.GetListByCategoryId(categoryId);
            else
                list = X.Bll.Product.GetListByCategoryName(categoryName);

            for (int i = 0; i < list.Count; i++)
            {
                if (0 == i % 5)
                    Response.Write("<tr>");

                Response.Write("<td style=\"height:170px;text-align:center;width:150px;\" valign=\"top\">");
                Response.Write(string.Format("<a href=\"/Product/{0}/{1}.aspx\" title=\"{2}\">", X.Common.StringUtils.StringToUrl(list[i].CategoryName, list[i].CategoryId), X.Common.StringUtils.StringToUrl(list[i].ProductName, list[i].ProductId), X.Common.StringUtils.HtmlDecode(list[i].ProductName)));
                Response.Write(string.Format("<img src=\"/Upload/{0}\" alt=\"{1}\" height=\"105px\" width=\"105px\" style=\"border:1px solid #cacaca;\"></a><br />", list[i].Photo[0].ImageNameEx, X.Common.StringUtils.HtmlDecode(list[i].ProductName)));
                Response.Write(string.Format("<a href=\"/Product/{0}/{1}.aspx\" title=\"{2}\">{3}</a>", X.Common.StringUtils.StringToUrl(list[i].CategoryName, list[i].CategoryId), X.Common.StringUtils.StringToUrl(list[i].ProductName, list[i].ProductId), X.Common.StringUtils.HtmlDecode(list[i].ProductName), list[i].ProductName));
                Response.Write("</td>");

                if (i == list.Count - 1 && 0 != i % 5)
                {
                    for (int j = 0; j < 5 - i % 5 - 1; j++)
                    {
                        Response.Write("<td style=\"height:170px;text-align:center;width:150px;\"></td>");
                    }
                }

                if (4 == i % 5)
                    Response.Write("</tr>");
            }
        %>
    </table>
</asp:Content>
